home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / rk_plot.zip / ALPHA.ASM < prev    next >
Assembly Source File  |  1991-05-13  |  7KB  |  266 lines

  1. ;***********************************************************************
  2. ; ALPHA.ASM     Version mit Bereichsprüfung bei AlphaPunktSetzen
  3. ; Copyright     (C) 1991, Hans-Jürgen Herrler und Dieter Sosna
  4. ;***********************************************************************
  5.                 
  6. DATA    SEGMENT BYTE PUBLIC
  7.  
  8.         ; Pascal Variable
  9.         EXTRN   AlphaMax                : word
  10.         EXTRN   AlphaMin                : word
  11.         EXTRN   maxTemp                 : word
  12.         EXTRN   minTemp                 : word
  13.         EXTRN   AlphaColor              : Byte;
  14.  
  15.         ; Pascal Prozedur (Unit Graph)
  16.         EXTRN   PutPixel                : far
  17.         EXTRN   GetMaxX                 : far
  18.         EXTRN   GetMaxY                 : far
  19.  
  20. DATA    ENDS
  21.  
  22. CODE    SEGMENT BYTE PUBLIC
  23.         ASSUME CS:CODE, DS:DATA
  24.  
  25.         PUBLIC  AlphaLine
  26.         PUBLIC  InitAlphaPuffer
  27.         PUBLIC  AlphaPufferAktualisieren
  28.  
  29. AlphaPunktSetzen PROC NEAR
  30.  
  31.         ; Input: ax = X, bx = Y
  32.         ; --> Punkt wird gesetzt in der Farbe AlphaColor
  33.  
  34.         push    ax
  35.         push    bx
  36.         push    cx
  37.         push    dx
  38.         push    bp
  39.  
  40.         ; Test, ob X und Y im zulässigen Bereich sind
  41.         test    ax,8000h
  42.         jnz     APS3
  43.         test    bx,8000h
  44.         jnz     APS3
  45.         mov     dx,ax
  46.         call    GetMaxX
  47.         cmp     dx,ax
  48.         jg      APS3
  49.         call    GetMaxY
  50.         cmp     bx,ax
  51.         jg      APS3
  52.         mov     ax,dx
  53.  
  54.         xor     dx,dx                   ; Boolean-Flag "Setzen" := False
  55.         mov     di,ax
  56.         shl     di,1                    ; di := 2 * X
  57.  
  58.         cmp     bx,[di+Offset AlphaMax] ; Y > AlphaMax[X] ?
  59.         jle     APS1
  60.  
  61.         inc     dx                      ; Setzen := True
  62.         cmp     bx,[di+Offset maxTemp]  ; Y > maxTemp[X] ?
  63.         jle     APS1
  64.         mov     [di+Offset maxTemp],bx  ; maxTemp[X] := Y
  65.  
  66. APS1:   cmp     bx,[di+Offset AlphaMin] ; Y < AlphaMin[X] ?
  67.         jnl     APS2
  68.         inc     dx                      ; Setzen := True
  69.         cmp     bx,[di+Offset minTemp]  ; Y < minTemp[X] ?
  70.         jnl     APS2
  71.         mov     [di+Offset minTemp],bx  ; minTemp[X] := Y
  72.  
  73. APS2:   cmp     dx,00                   ; Setzen = False ?
  74.         je      APS3
  75.         push    ax                      ; Parameter übergeben: x, y, Farbe
  76.         push    bx
  77.         xor     ax,ax
  78.         mov     al,[AlphaColor]
  79.         push    ax
  80.         call    PUTPIXEL                ; Unit Graph
  81.  
  82. APS3:   pop     bp
  83.         pop     dx
  84.         pop     cx
  85.         pop     bx
  86.         pop     ax
  87.         ret
  88.  
  89. AlphaPunktSetzen ENDP
  90.  
  91. Betrag          PROC    NEAR
  92.         ; Input:        cx = Integer1   dx = Integer2
  93.         ; Output:       cx = Absoluter Betrag(Integer1 - Integer2)
  94.         ;               dx = 1, falls Integer2 >= Integer1, sonst dx = -1
  95.  
  96.         add     cx,8000h
  97.         add     dx,8000h
  98.         cmp     dx,cx
  99.         jc      Betr1
  100.  
  101.         ; falls Integer2 >= Integer1
  102.         push    cx
  103.         mov     cx,dx
  104.         pop     dx
  105.         sub     cx,dx
  106.         mov     dx,0001h
  107.         jmp     Betr2
  108.  
  109.         ; falls Integer2 < Integer1
  110. Betr1:  sub     cx,dx
  111.         mov     dx,0FFFFh
  112.  
  113. Betr2:  ret
  114.  
  115. Betrag          ENDP
  116.  
  117. AlphaLine       PROC    FAR
  118.  
  119.         ; Parameter auf dem Stack
  120. P2X     EQU     6
  121. P2Y     EQU     P2X + 2
  122. P1X     EQU     P2Y + 2
  123. P1Y     EQU     P1X + 2
  124.         ; lokale Variablen
  125. XStep   EQU     -2
  126. YStep   EQU     XStep - 2
  127. DeltaX  EQU     YStep - 2
  128. DeltaY  EQU     DeltaX - 2
  129.  
  130.         push    bp
  131.         mov     bp,sp
  132.         sub     sp,0008h                ; Platz für lokale Variablen
  133.  
  134.         ; DeltaX := Abs(LongInt(P1X)-LongInt(P2X))
  135.  
  136.         mov     cx,[bp+P1X]
  137.         mov     ax,cx                   ; ax = X
  138.         mov     dx,[bp+P2X]
  139.         call    Betrag
  140.         mov     [bp+DeltaX],cx
  141.         mov     [bp+XStep],dx
  142.  
  143.         ; DeltaY := Abs(LongInt(P1Y)-LongInt(P2Y))
  144.         mov     cx,[bp+P1Y]
  145.         mov     bx,cx                   ; bx = Y
  146.         mov     dx,[bp+P2Y]
  147.         call    Betrag
  148.         mov     [bp+DeltaY],cx
  149.         mov     [bp+YStep],dx
  150.  
  151.         ; IF DeltaX >= DeltaY THEN Flach := True ELSE Flach := False
  152.         push    ax
  153.         mov     ax,[bp+DeltaX]
  154.         cmp     ax,[bp+DeltaY]
  155.         pop     ax
  156.         jc      Steil
  157.  
  158.         ; Flach: Hier ist X die unabhängige Variable
  159.         mov     dx,[bp+DeltaX]
  160.         mov     cx,dx                   ; cx = Schleifenzähler
  161.         shr     dx,1                    ; dx = Control = DeltaX / 2
  162.         call    AlphaPunktSetzen
  163.  
  164. Loop1:  add     ax,[bp+XStep]           ; Inc(X, XStep)
  165.         sub     dx,[bp+DeltaY]          ; Dec(Control, DeltaY)
  166.         jg      ALine1
  167.  
  168.         ; Falls Control <= 0:
  169.         add     bx,[bp+YStep]           ; Inc(Y, YStep)
  170.         add     dx,[bp+DeltaX]          ; Inc(Control, DeltaX)
  171.  
  172. ALine1: call    AlphaPunktSetzen
  173.         loop    Loop1
  174.         jmp     ALine3
  175.  
  176. Steil:  mov     dx,[bp+DeltaY]
  177.         mov     cx,dx                   ; cx = Schleifenzähler
  178.         shr     dx,1                    ; dx = Control = DeltaY / 2
  179.         call    AlphaPunktSetzen
  180.  
  181. Loop2:  add     bx,[bp+YStep]           ; Inc(Y, YStep)
  182.         sub     dx,[bp+DeltaX]          ; Dec(Control, DeltaX)
  183.         jg      ALine2
  184.  
  185.         ; Falls Control <= 0:
  186.         add     ax,[bp+XStep]           ; Inc(X, XStep)
  187.         add     dx,[bp+DeltaY]          ; Inc(Control, DeltaY)
  188.  
  189. ALine2: call    AlphaPunktSetzen
  190.         loop    Loop2
  191.  
  192. ALine3: mov     sp,bp
  193.         pop     bp
  194.         ret     0008h
  195.  
  196. AlphaLine       ENDP
  197.  
  198. InitAlphaPuffer PROC FAR
  199.  
  200.         cld                             ; Richtung: aufsteigend
  201.         push    ds
  202.         pop     es
  203.         call    GetMaxX
  204.         inc     ax
  205.         push    ax
  206.  
  207.         mov     cx,ax
  208.         mov     ax,0FFFFh
  209.         mov     di,Offset AlphaMax
  210.         rep
  211.         stosw
  212.  
  213.         call    GetMaxY
  214.         inc     ax
  215.         mov     di,Offset AlphaMin
  216.         pop     cx
  217.         push    cx
  218.         rep
  219.         stosw
  220.  
  221.         mov     si,Offset AlphaMax
  222.         mov     di,Offset maxTemp
  223.         pop     cx
  224.         push    cx
  225.         rep
  226.         movsw
  227.  
  228.         mov     si,Offset AlphaMin
  229.         mov     di,Offset minTemp
  230.         pop     cx
  231.         rep
  232.         movsw
  233.  
  234.         ret
  235.  
  236. InitAlphaPuffer ENDP
  237.  
  238. AlphaPufferAktualisieren        PROC FAR
  239.  
  240.         cld                             ; Richtung: aufsteigend
  241.         push    ds
  242.         pop     es
  243.         call    GetMaxX
  244.         inc     ax
  245.         push    ax
  246.  
  247.         mov     si,Offset maxTemp
  248.         mov     di,Offset AlphaMax
  249.         pop     cx
  250.         push    cx
  251.         rep
  252.         movsw
  253.  
  254.         mov     si,Offset minTemp
  255.         mov     di,Offset AlphaMin
  256.         pop     cx
  257.         rep
  258.         movsw
  259.  
  260.         ret
  261.  
  262. AlphaPufferAktualisieren        ENDP
  263.  
  264.         ENDS
  265.         END
  266.